﻿using System.Web.UI.WebControls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StockholmsStad.Web.UI.Class.Utilities;

namespace StockholmsStad.Web.UI.Test
{
    /// <summary>
    ///This is a test class for ListItemSetTest and is intended
    ///to contain all ListItemSetTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ListItemSetTest
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        #region Additional test attributes

        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //

        #endregion

        /// <summary>
        ///A test for IsReadOnly
        ///</summary>
        [TestMethod()]
        public void IsReadOnlyTest()
        {
            var target = new ListItemSet();
            bool actual;
            actual = target.IsReadOnly;
            Assert.IsFalse(actual);
        }

        /// <summary>
        ///A test for Count
        ///</summary>
        [TestMethod()]
        public void CountTest()
        {
            var target = new ListItemSet();
            target.Add(new ListItem("Kalle", "Svensson"));
            target.Add(new ListItem("Kalle", "Ohlsson"));
            int actual;
            actual = target.Count;
            Assert.AreEqual(1, actual);
        }

        /// <summary>
        ///A test for System.Collections.IEnumerable.GetEnumerator
        ///</summary>
        [TestMethod()]
        public void GetEnumeratorTest()
        {
            var target = new ListItemSet();
            target.Add(new ListItem("Kalle", "Svensson"));
            target.Add(new ListItem("Kalle", "Ohlsson"));
            foreach (ListItem item in target)
            {
                Assert.AreEqual(item.Text, "Kalle");
            }
        }

        /// <summary>
        ///A test for Remove
        ///</summary>
        [TestMethod()]
        public void RemoveTest()
        {
            var target = new ListItemSet();
            var item = new ListItem("Kalle", "Svensson");
            target.Add(item);
            Assert.AreEqual(1, target.Count);
            target.Remove(item);
            Assert.AreEqual(0, target.Count);
        }

        /// <summary>
        ///A test for CopyTo
        ///</summary>
        [TestMethod()]
        public void CopyToTest()
        {
            var target = new ListItemSet(); 
            var item = new ListItem("Kalle", "Svensson");
            target.Add(item);
            Assert.AreEqual(1, target.Count);
            var array = new ListItem[1];
            int arrayIndex = 0;
            target.CopyTo(array, arrayIndex);
            Assert.AreEqual(item, array[0]);
        }

        /// <summary>
        ///A test for Contains
        ///</summary>
        [TestMethod()]
        public void ContainsTest()
        {
            var target = new ListItemSet();
            var item = new ListItem("Kalle", "Svensson");
            target.Add(item);
            Assert.IsTrue(target.Contains(item));
        }

        /// <summary>
        ///A test for Clear
        ///</summary>
        [TestMethod()]
        public void ClearTest()
        {
            var target = new ListItemSet();
            var item = new ListItem("Kalle", "Svensson");
            var item2 = new ListItem("Ola", "Svensson");
            target.Add(item);
            target.Add(item2);
            Assert.AreEqual(2, target.Count);
            target.Clear();
            Assert.AreEqual(0, target.Count);
        }

        /// <summary>
        ///A test for Add
        ///</summary>
        [TestMethod()]
        public void AddTest()
        {
            var target = new ListItemSet();
            var item = new ListItem("Kalle", "Svensson");
            var item2 = new ListItem("Ola", "Svensson");
            var item3 = new ListItem("Kalle", "Ohlsson");
            var item4 = new ListItem("Stina", "Stinsson");
            target.Add(item);
            target.Add(item2);
            target.Add(item3);
            target.Add(item4);
            Assert.AreEqual(3, target.Count);
            Assert.IsTrue(target.Contains(item));
            Assert.IsTrue(target.Contains(item2));
            Assert.IsFalse(target.Contains(item3));
            Assert.IsTrue(target.Contains(item4));
        }

        /// <summary>
        ///A test for Add
        ///</summary>
        [TestMethod()]
        public void AddTest2()
        {
            var target = new ListItemSet
                             {
                                 new ListItem("Kalle", "Svensson"),
                                 new ListItem("Ola", "Svensson"),
                                 new ListItem("Kalle", "Ohlsson"),
                                 new ListItem("Stina", "Stinsson")
                             };
            Assert.AreEqual(3, target.Count);
            Assert.IsTrue(target.Contains(new ListItem("Kalle", "Svensson")));
            Assert.IsTrue(target.Contains(new ListItem("Ola", "Svensson")));
            Assert.IsFalse(target.Contains(new ListItem("Kalle", "Ohlsson")));
            Assert.IsTrue(target.Contains(new ListItem("Stina", "Stinsson")));
        }

        /// <summary>
        ///A test for ListItemSet Constructor
        ///</summary>
        [TestMethod()]
        public void ListItemSetConstructorTest()
        {
            var target = new ListItemSet();
            Assert.IsNotNull(target);
        }
    }
}